package com.wenan.ui.controls.charts.expand
{
	import com.amcharts.AmPieChart;
	import com.amcharts.axes.CategoryAxis;
	import com.amcharts.axes.ValueAxis;
	import com.amcharts.chartClasses.AmBalloon;
	import com.amcharts.chartClasses.AmChart;
	import com.amcharts.chartClasses.AmRectangularChart;
	import com.amcharts.chartClasses.ChartCursor;
	import com.amcharts.chartClasses.ChartScrollbar;
	
	import mx.containers.Canvas;
	
	public class AmChartSpecial extends Canvas 
	{
		private var _amChart:AmChart;
		private var _type:Number;
		private var _dataProvider:Object;
		private var _categoryField:String;
		private var _valueAxes:Array = new Array();
		/**
		 * 横纵向与否   默认为false，横向
		 * */
		private var _rotate:Boolean;
		
		/**
		 * type决定报表的类型。1为尖锐线
		 * 2平滑线
		 * 3柱状图
		 * 4梯状图
		 * 5散点图
		 * 6饼形图
		 * 默认是柱状图
		 * */
		public function AmChartSpecial(type:Number=0, dataProvider:Object=null)
		{
			super();
			if (type != 0) {
				this.type = type;
				if (type == 5)
				{
					_amChart = new AmXYChartExpand();
				} else if (type == 6)
				{
					_amChart = new AmPieChartExpand();
				} else 
				{
					_amChart = new AmSerialChartExpand();
				}
				_amChart.percentWidth = 100;
				_amChart.percentHeight = 100;
				amChart.dataProvider = dataProvider;
				_amChart.setStyle("marginBottom", 0); 
				_amChart.setStyle("marginTop", 5); 
				_amChart.setStyle("marginLeft", 5); 
				_amChart.setStyle("marginRight", 5); 
				_amChart.setStyle("plotAreaFillColors", [0xF1F8FE]);
				this.addChild(amChart);
			}
		}

		public function get amChart():AmChart
		{
			return _amChart;
		}

		public function get dataProvider():Object
		{
			return amChart.dataProvider;
		}

		public function get categoryField():String
		{
			return _categoryField;
		}

		public function get type():Number
		{
			return _type;
		}
		
		public function set type(value:Number):void
		{
			_type = value;
			if (type == 5)
			{
				_amChart = new AmXYChartExpand();
			} else if (type == 6)
			{
				_amChart = new AmPieChartExpand();
			} else 
			{
				_amChart = new AmSerialChartExpand();
			}
			_amChart.percentWidth = 100;
			_amChart.percentHeight = 100;
			_amChart.setStyle("marginBottom", 0); 
			_amChart.setStyle("marginTop", 5); 
			_amChart.setStyle("marginLeft", 5); 
			_amChart.setStyle("marginRight", 5);
			_amChart.setStyle("plotAreaFillColors", [0xF1F8FE]);
		}
		
		public function set dataProvider(value:Object):void
		{
			amChart.dataProvider = value;
		}
		/**
		 * 对于柱状、簇状、散点设置横坐标
		 * */
		public function set categoryField(value:String):void
		{
			if (amChart is AmSerialChartExpand)
			{
				var temp:AmSerialChartExpand = changeToAmSerialChartExpand();
				temp.categoryField = value;
				_categoryField = value;
			}
		}
		
		/**
		 * 对于柱状、簇状、散点设置x轴属性
		 * */
		public function categoryAxis(value:CategoryAxis):void
		{
			if (amChart is AmSerialChartExpand)
			{
				var temp:AmSerialChartExpand = changeToAmSerialChartExpand();
				temp.categoryAxis = value;
			}
		}

		/**
		 * 将amChart强转为AmSerialChartExpand
		 * */
		private function changeToAmSerialChartExpand():AmSerialChartExpand
		{
			return amChart as AmSerialChartExpand;
		}
		
		/**
		 * 将amChart强转为AmXYChartExpand
		 * */
		private function changeToAmXYChartExpand():AmXYChartExpand
		{
			return amChart as AmXYChartExpand;
		}
		
		/**
		 * 将amChart强转为AmPieChartExpand
		 * */
		private function changeToAmPieChartExpand():AmPieChartExpand
		{
			return amChart as AmPieChartExpand;
		}
		
		/**
		 * 将amChart强转为AmRectangularChart
		 * */
		private function changeToAmRectangularChart():AmRectangularChart
		{
			return amChart as AmRectangularChart;
		}

		public function get rotate():Boolean
		{
			return _rotate;
		}

		public function set rotate(value:Boolean):void
		{
			_rotate = value;
			if (amChart is AmSerialChartExpand)
			{
				var temp:AmSerialChartExpand = changeToAmSerialChartExpand();
				temp.rotate = value;
			}
		}

		public function get graphsList():Array
		{
			if (amChart is AmRectangularChart)
			{
				var temp:AmRectangularChart = changeToAmRectangularChart();
				return temp.graphs;
			}
			return null;
		}

		/**
		 * 对于柱状、簇状、散点设置y轴属性
		 * */
		public function valueAxes(value:ValueAxis):void
		{
			if (amChart is AmSerialChartExpand)
			{
				var temp:AmSerialChartExpand = changeToAmSerialChartExpand();
				temp.valueAxes.push(value);
			}
		}
		
		/**
		 * 对于散点图x、 y轴设置
		 * */
		public function valueAxesSpecial(valueAxes:Array):void
		{
			if (amChart is AmXYChartExpand)
			{
				var temp:AmXYChartExpand = changeToAmXYChartExpand();
				temp.valueAxes = valueAxes;
			}
		}
		
		/**
		 * 对于散点图，缓加载点。
		 * */
		public function startDuration(value:Number):void
		{
			/*
			if (amChart is AmXYChartExpand)
			{
				var temp:AmXYChartExpand = changeToAmXYChartExpand();
				
			}
			*/
			amChart.setStyle("startDuration", value);
		}
		
		/**
		 * 缩放工具栏
		 * */
		public function chartScrollbar(chartScrollbar:ChartScrollbar):void
		{
			if (amChart is AmXYChartExpand)
			{
				var temp:AmXYChartExpand = changeToAmXYChartExpand();
				temp.chartScrollbar = chartScrollbar;
				return;
			} else if (amChart is AmSerialChartExpand)
			{
				var asce:AmSerialChartExpand = changeToAmSerialChartExpand();
				asce.chartScrollbar = chartScrollbar;
			}
//			amChart.chartScrollbar = chartScrollbar;
		}
		
		public override function set id(value:String):void
		{
			if (amChart)
				amChart.id = value;
		}
		
		public override function get id():String
		{
			if (amChart)
				return amChart.id;
			return null;
		}
		
		public function set colors(colors:Array):void
		{
			_amChart.setStyle("colors", colors);
		}
		
		public function set dataUpdated(fun:Function):void
		{
			if (amChart is AmSerialChartExpand)
			{
				var temp:AmSerialChartExpand = changeToAmSerialChartExpand();
				temp.setStyle("dataUpdated", fun);
			}
		}
		
		public function zoomToIndexes(start:Number, end:Number):void
		{
			if (amChart is AmSerialChartExpand)
			{
				var temp:AmSerialChartExpand = changeToAmSerialChartExpand();
				temp.zoomToIndexes(start, end);
			}
		}
		
		/**
		 * 修饰tip
		 * */
		public function balloon(value:AmBalloon):void {
			_amChart.balloon = value;
		}
		
		/**
		 * tip移动时，指定小点移动的方式。
		 * */
		public function chartCursor(chartCursor:ChartCursor):void {
			if (amChart is AmRectangularChart)
			{
				var temp:AmRectangularChart = changeToAmRectangularChart();
				temp.chartCursor = chartCursor;
			}
		}
		
		/**
		 * 针对饼形图的标题
		 * */
		public function titleField(value:String):void {
			if (amChart is AmPieChartExpand)
			{
				var temp:AmPieChartExpand = changeToAmPieChartExpand();
				temp.titleField = value;
			}
		}
		
		/**
		 * 针对饼形图的值
		 * */
		public function valueField(value:String):void
		{
			if (amChart is AmPieChartExpand)
			{
				var temp:AmPieChartExpand = changeToAmPieChartExpand();
				temp.valueField = value;
			}
		}

	}
}